import { Component } from 'react';
import { memoize } from './utils';

export default class extends Component {

  state = {
    count: 0,
  };

  // 用props或者state的更新情况限制组件的render
  // shouldComponentUpdate (nextProps, nextState) {
  //   if (nextState.count === this.state.count) {
  //     return false;
  //   }
  //   return true;
  // }

  componentDidMount () {
    setInterval(() => {
      this.setState({ count: 0 });
    }, 1000);
  }

  // 用缓存函数缓存同参数上次留存结构
  myRender = memoize((state, props) => {
    console.log('render');
    return (
      <div className="App">
        { state.count }
      </div>
    );
  });

  render () {
    return this.myRender(this.state, this.props);
  }

}